package com.efast.dmom.mgmt.controller.les;

import com.efast.cafe.framework.bean.ResultBean;
import com.efast.dmom.mgmt.entity.les.TwDocOrderDetails;
import com.efast.dmom.mgmt.service.les.TwDocOrderDetailsService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import io.swagger.annotations.Api;

/**
 * 出库订单表: TW_DOC_ORDER_DETAILS
 * @author chlp
 */
@Controller
@RequestMapping(value="/twDocOrderDetails")
@Api(value = "/twOutbTaskDetail", description = "出库订单detail")
public class TwDocOrderDetailsController {
	
	@Autowired
	private TwDocOrderDetailsService twDocOrderDetailsService;
	
	/**
	 * 出库订单details的新增  后台需哟啊生成：行号/状态/
	 * @param twDocAsnHeader
	 * @return
	 */
	@RequestMapping(value = "/save" , method=RequestMethod.POST)
	public @ResponseBody ResultBean save(@RequestBody TwDocOrderDetails twDocOrderDetails){
		ResultBean result=new ResultBean(true,"'");
		twDocOrderDetailsService.insertNonEmptyTwDocOrderDetails(twDocOrderDetails);
		return result;
	}
	
	
	/**
	 * 【关闭】
	 * g)点击“按单关闭”，关闭整单
	 * @param twDocAsnHeader
	 * @return
	 */
	@RequestMapping(value = "/close" , method=RequestMethod.POST)
	public @ResponseBody ResultBean close(@RequestBody TwDocOrderDetails twDocOrderDetails){
		ResultBean result=new ResultBean(true,"'");
		twDocOrderDetailsService.updateNonEmptyTwDocOrderDetailsById(twDocOrderDetails);
		return result;
	}
	
	
	/**
	 * 【删除】
	 * f)点击“删除”，可以删除出库订单数据，可以删除明细，也可以整单删除
	 * @param twDocAsnHeader
	 * @return
	 */
	@RequestMapping(value = "/delete" , method=RequestMethod.POST)
	public @ResponseBody ResultBean delete(@RequestBody TwDocOrderDetails twDocOrderDetails){
		ResultBean result=new ResultBean(true,"'");
		twDocOrderDetailsService.deleteTwDocOrderDetailsById(twDocOrderDetails.getTwDocOrderDetailsId());
		return result;
	}
	
	
	/**
	 * 【按行分配】
	 * j)点击“按行分配”，实现某行明细分配
	 * @param twDocAsnHeader
	 * @return
	 */
	@RequestMapping(value = "/distributionByBill" , method=RequestMethod.POST)
	public @ResponseBody ResultBean distributionByBill(@RequestBody TwDocOrderDetails twDocOrderDetails){
		ResultBean result=new ResultBean(true,"'");
		String executeProcGetCode = twDocOrderDetailsService.executeProcGetCode();
		twDocOrderDetailsService.distributionByBill(twDocOrderDetails,executeProcGetCode);
		return result;
	}
	
	
	/**
	 * 【按行生成拣货任务】
	 *	l)点击“按行生成拣货任务”，分配完成后按照某行产生拣货任务
	 * @param twDocAsnHeader
	 * @return
	 */
	@RequestMapping(value = "/generatePickingByBill" , method=RequestMethod.POST)
	public @ResponseBody ResultBean generatePickingByBill(@RequestBody TwDocOrderDetails twDocOrderDetails){
		twDocOrderDetailsService.generatePickingByBill(twDocOrderDetails);
		ResultBean result=new ResultBean(true,"'");
		return result;
	}
	
	
	/**
	 * 【按行取消分配】
	 *	n)点击“按行取消分配”，某行取消分配，只有拣货确认之前可以取消分配
	 * @param twDocAsnHeader
	 * @return
	 */
	@RequestMapping(value = "/cancelDistribution" , method=RequestMethod.POST)
	public @ResponseBody ResultBean cancelDistribution(@RequestBody TwDocOrderDetails twDocOrderDetails){
		ResultBean result=new ResultBean(true,"'");
		twDocOrderDetailsService.cancelDistribution(twDocOrderDetails);
		return result;
	}
	

}
